<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Kefu extends CIC_A_Controller
{
	var $kefu_type;		//客服类型
	
	function __construct()
	{
		parent::__construct();
		$this->init();
	}
	private function init()
	{
		$this->kefu_type = $this->cic_model->get_all('kefu_type');
	}
	function index()
	{
		$this->admin_priv(__METHOD__);
		$data['kefu_user'] = $this->cic_model->get_all('kefu_user','',array('user_sort','desc'));
		$this->load->view('admin/kefu/index',$data);
	}
	function add()
	{
		$data['kefu_type'] = $this->kefu_type;
		$this->load->view('admin/kefu/add',$data);
	}
	function edit()
	{
		$data['kefu_type'] = $this->kefu_type;
		$data['kefu_user'] = $this->cic_model->get_one('kefu_user',array('user_id'=>$this->uri->segment(4)));
		$this->load->view('admin/kefu/edit',$data);
	}
	
	function delete()
	{
		$this->admin_priv(__METHOD__);
		if($this->cic_model->delete('kefu_user',array('user_id'=>$this->uri->segment(4))))
		{
			if($this->input->is_ajax_request())
			{
				echo 1;
			}
		}
	}
	function add_kefu()
	{
		$this->admin_priv(__METHOD__);
		$this->validate('kefu','admin/kefu/add');
		if($this->cic_model->insert('kefu_user',$this->input->post()))
			$this->message->msg('添加成功！',site_url('admin/kefu/index'));
		else
			$this->message->msg('添加失败！请重试！',site_url('admin/kefu/add'));
	}
	
	function update_kefu()
	{
		$this->admin_priv(__METHOD__);
		$this->validate('kefu','admin/kefu/edit/'.$this->uri->segment(4));
		if($this->cic_model->update('kefu_user',$this->input->post(),array('user_id'=>$this->uri->segment(4))))
		{
			$this->message->msg('修改成功！',site_url('admin/kefu/index'));
		}else{
			$this->message->msg('未做任何修改！',site_url('admin/kefu/edit/'.$this->uri->segment(4)));
		}
	}

}